part of 'component.dart';

class ExpandedFilledButton extends StatelessWidget {
  const ExpandedFilledButton({
    Key? key,
    required this.text,
    this.textColor,
    this.fontSize,
    this.backgroundColor,
    this.height,
    this.onPressed,
    this.margin,
    this.enable = true,
  }) : super(key: key);
  final String text;
  final Color? textColor;
  final double? fontSize;
  final Color? backgroundColor;
  final double? height;
  final EdgeInsets? margin;
  final VoidCallback? onPressed;
  final bool enable;
  @override
  Widget build(BuildContext context) {
    EdgeInsets mar = margin ?? const EdgeInsets.symmetric(horizontal: 15);
    var h = height ?? 44.r;
    var w = context.mediaQuery.size.width - mar.horizontal;
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Container(
          alignment: Alignment.center,
          margin: mar,
          child: FilledButton(
            onPressed: enable ? onPressed : null,
            style: ButtonStyle(
                backgroundColor: MaterialStatePropertyAll(enable
                    ? (backgroundColor ?? ITheme.selectedColor)
                    : ITheme.disableBgColor),
                foregroundColor:
                    MaterialStatePropertyAll(textColor ?? Colors.white),
                minimumSize: MaterialStatePropertyAll(Size(w, h))),
            child: Text(
              text,
            ),
          ),
        )
      ],
    );
  }
}

class TextBtn extends StatelessWidget {
  const TextBtn({
    Key? key,
    this.title,
    this.onTap,
    this.fgColor,
    this.bgColor,
    this.fixedSize,
    this.borderSide,
    this.radius,
    this.textStyle,
    this.padding,
  }) : super(key: key);

  final String? title;
  final Color? fgColor;
  final VoidCallback? onTap;
  final Color? bgColor;
  final Size? fixedSize;
  final BorderSide? borderSide;
  final BorderRadius? radius;
  final TextStyle? textStyle;
  final EdgeInsets? padding;

  @override
  Widget build(BuildContext context) {
    return TextButton(
      style: ButtonStyle(
        padding: MaterialStatePropertyAll(
            fixedSize == null ? padding : EdgeInsets.zero),
        textStyle: MaterialStatePropertyAll(
            textStyle ?? TextStyle(color: Colors.white, fontSize: 15.sp)),
        foregroundColor: MaterialStateProperty.all(
            fgColor ?? ITheme.buttonTheme.colorScheme?.primary),
        backgroundColor: MaterialStateProperty.all(
            bgColor ?? ITheme.buttonTheme.colorScheme?.background),
        fixedSize: MaterialStatePropertyAll(
          fixedSize ??
              Size(ITheme.buttonTheme.minWidth, ITheme.buttonTheme.height),
        ),
        minimumSize: MaterialStatePropertyAll(fixedSize ??
            Size(ITheme.buttonTheme.minWidth, ITheme.buttonTheme.height)),
        side: MaterialStateBorderSide.resolveWith((states) => borderSide),
        tapTargetSize: MaterialTapTargetSize.shrinkWrap,
        shape: MaterialStatePropertyAll(
          RoundedRectangleBorder(
              side: borderSide ?? BorderSide.none,
              borderRadius: radius ?? BorderRadius.zero),
        ),
      ),
      onPressed: onTap,
      child: Text(title ?? ''),
    );
  }
}

class IconBtn extends StatelessWidget {
  const IconBtn({
    Key? key,
    this.title,
    this.iconData,
    this.onTap,
    this.fgColor,
    this.bgColor,
    this.size,
    this.iconSize,
    this.borderSide,
    this.radius,
    this.textStyle,
  }) : super(key: key);

  final String? title;
  final IconData? iconData;
  final Color? fgColor;
  final VoidCallback? onTap;
  final Color? bgColor;
  final double? size;
  final double? iconSize;
  final BorderSide? borderSide;
  final BorderRadius? radius;
  final TextStyle? textStyle;

  @override
  Widget build(BuildContext context) {
    var isz = iconSize ?? 20.r;
    var ns = max(size ?? 40.r, isz);
    double pad = iconData == null ? 0 : (ns - isz) / 2;

    return TextButton(
      style: ButtonStyle(
        textStyle:
            MaterialStatePropertyAll(textStyle ?? ITheme.text.titleSmall),
        foregroundColor:
            MaterialStateProperty.all(fgColor ?? const Color(0xff666666)),
        backgroundColor:
            bgColor == null ? null : MaterialStateProperty.all(bgColor),
        fixedSize: MaterialStatePropertyAll(Size(ns, ns)),
        minimumSize: MaterialStatePropertyAll(Size(ns, ns)),
        padding: MaterialStatePropertyAll(EdgeInsets.all(pad)),
        tapTargetSize: MaterialTapTargetSize.shrinkWrap,
        side: MaterialStateBorderSide.resolveWith((states) => borderSide),
        shape: MaterialStatePropertyAll(
          RoundedRectangleBorder(
              side: borderSide ?? BorderSide.none,
              borderRadius: radius ?? BorderRadius.zero),
        ),
      ),
      onPressed: onTap,
      child: iconData != null
          ? Icon(
              iconData,
              size: isz,
            )
          : Text(title ?? ''),
    );
  }
}
